using RxjhServer.DbClss;
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

namespace RxjhServer
{
	public class CheckCopy : Form
	{
		public delegate void MyInvoke(string str);

		private Button button1;

		private IContainer components = null;

		private GroupBox groupBox1;

		private GroupBox groupBox2;

		private MenuStrip menuStrip1;

		private RadioButton radioButton2;

		private RadioButton radioButton3;

		private RadioButton radioButton4;

		private RadioButton radioButton7;

		private TextBox textBox1;

		private ToolStripMenuItem 帮助ToolStripMenuItem;

		private DataTable 个人仓库;

		private DataTable 个人仓库1;

		private DataTable 人物自身;

		private DataTable 人物自身1;

		private ToolStripMenuItem 说明ToolStripMenuItem;

		private DataTable 综合仓库;

		private DataTable 综合仓库1;

		public CheckCopy()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			人物自身 = null;
			个人仓库 = null;
			综合仓库 = null;
			人物自身1 = null;
			个人仓库1 = null;
			综合仓库1 = null;
			if (World.allConnectedChars.Count > 0)
			{
				MessageBox.Show("有人物在线不能查询!", "提示");
				return;
			}
			SetText("开始查询....");
			button1.Enabled = false;
			string sqlCommand = "select FLD_ID,FLD_NAME,FLD_WEARITEM,FLD_ITEM from [TBL_人物数据]";
			string sqlCommand2 = "select FLD_ID,FLD_NAME,FLD_ITEM from [TBL_个人仓库]";
			string sqlCommand3 = "select FLD_ID,FLD_ITEM from [TBL_综合仓库]";
			人物自身 = DBA.GetDBToDataTable(sqlCommand, "GameServer");
			个人仓库 = DBA.GetDBToDataTable(sqlCommand2, "GameServer");
			综合仓库 = DBA.GetDBToDataTable(sqlCommand3, "GameServer");
			if (radioButton2.Checked || radioButton7.Checked)
			{
				if (人物自身.Rows.Count != 0)
				{
					if (radioButton2.Checked)
					{
						for (int i = 0; i < 人物自身.Rows.Count; i++)
						{
							byte[] src = (byte[])人物自身.Rows[i]["FLD_ITEM"];
							string id = 人物自身.Rows[i]["FLD_ID"].ToString();
							string name = 人物自身.Rows[i]["FLD_NAME"].ToString();
							for (int j = 0; j < 36; j++)
							{
								byte[] array = new byte[4];
								Buffer.BlockCopy(src, j * 73, array, 0, 4);
								int num = BitConverter.ToInt32(array, 0);
								if (num != 0)
								{
									try
									{
										ThreadParameter state = new ThreadParameter(num, id, name, 0);
										ThreadPool.QueueUserWorkItem(查物品, state);
									}
									catch (Exception ex)
									{
										SetText("查询背包线程出错" + ex.ToString());
									}
								}
							}
						}
						SetText("查询完毕!!!!");
					}
					else
					{
						for (int k = 0; k < 人物自身.Rows.Count; k++)
						{
							byte[] src2 = (byte[])人物自身.Rows[k]["FLD_WEARITEM"];
							string id2 = 人物自身.Rows[k]["FLD_ID"].ToString();
							string name2 = 人物自身.Rows[k]["FLD_NAME"].ToString();
							for (int l = 0; l < 15; l++)
							{
								byte[] array2 = new byte[4];
								Buffer.BlockCopy(src2, l * 73, array2, 0, 4);
								int num2 = BitConverter.ToInt32(array2, 0);
								if (num2 != 0)
								{
									try
									{
										ThreadParameter state2 = new ThreadParameter(num2, id2, name2, 1);
										ThreadPool.QueueUserWorkItem(查物品, state2);
									}
									catch (Exception ex2)
									{
										SetText("查询已穿装备线程出错" + ex2.ToString());
									}
								}
							}
						}
						SetText("查询完毕!!!!");
					}
				}
				人物自身.Dispose();
			}
			else if (radioButton3.Checked)
			{
				if (个人仓库.Rows.Count != 0)
				{
					for (int m = 0; m < 个人仓库.Rows.Count; m++)
					{
						byte[] src3 = (byte[])个人仓库.Rows[m]["FLD_ITEM"];
						for (int n = 0; n < 60; n++)
						{
							byte[] array3 = new byte[4];
							string id3 = 个人仓库.Rows[m]["FLD_ID"].ToString();
							string name3 = 个人仓库.Rows[m]["FLD_NAME"].ToString();
							Buffer.BlockCopy(src3, n * 73, array3, 0, 4);
							int num3 = BitConverter.ToInt32(array3, 0);
							if (num3 != 0)
							{
								try
								{
									ThreadParameter state3 = new ThreadParameter(num3, id3, name3, 2);
									ThreadPool.QueueUserWorkItem(查物品, state3);
								}
								catch (Exception ex3)
								{
									SetText("查询个人仓库线程出错" + ex3.ToString());
								}
							}
						}
					}
					SetText("查询完毕!!!!");
				}
				个人仓库.Dispose();
			}
			else
			{
				if (综合仓库.Rows.Count != 0)
				{
					for (int num4 = 0; num4 < 综合仓库.Rows.Count; num4++)
					{
						byte[] src4 = (byte[])综合仓库.Rows[num4]["FLD_ITEM"];
						for (int num5 = 0; num5 < 60; num5++)
						{
							byte[] array4 = new byte[4];
							string id4 = 综合仓库.Rows[num4]["FLD_ID"].ToString();
							Buffer.BlockCopy(src4, num5 * 73, array4, 0, 4);
							int num6 = BitConverter.ToInt32(array4, 0);
							if (num6 != 0)
							{
								try
								{
									ThreadParameter state4 = new ThreadParameter(num6, id4, "", 3);
									ThreadPool.QueueUserWorkItem(查物品, state4);
								}
								catch (Exception ex4)
								{
									SetText("查询综合仓库线程出错" + ex4.ToString());
								}
							}
						}
					}
					SetText("查询完毕!!!!");
				}
				综合仓库.Dispose();
			}
			button1.Enabled = true;
		}

		private void CheckCopy_FormClosing(object sender, FormClosingEventArgs e)
		{
			try
			{
				if (人物自身 != null)
				{
					人物自身 = null;
				}
				if (人物自身1 != null)
				{
					人物自身1 = null;
				}
				if (个人仓库 != null)
				{
					个人仓库 = null;
				}
				if (个人仓库1 != null)
				{
					个人仓库1 = null;
				}
				if (综合仓库 != null)
				{
					综合仓库 = null;
				}
				if (综合仓库1 != null)
				{
					综合仓库1 = null;
				}
			}
			catch
			{
			}
		}

		private void CheckCopy_Load(object sender, EventArgs e)
		{
			ThreadPool.SetMinThreads(100, 100);
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent()
		{
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RxjhServer.CheckCopy));
			groupBox1 = new System.Windows.Forms.GroupBox();
			radioButton7 = new System.Windows.Forms.RadioButton();
			radioButton4 = new System.Windows.Forms.RadioButton();
			radioButton3 = new System.Windows.Forms.RadioButton();
			radioButton2 = new System.Windows.Forms.RadioButton();
			groupBox2 = new System.Windows.Forms.GroupBox();
			textBox1 = new System.Windows.Forms.TextBox();
			button1 = new System.Windows.Forms.Button();
			menuStrip1 = new System.Windows.Forms.MenuStrip();
			说明ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
			帮助ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
			groupBox1.SuspendLayout();
			groupBox2.SuspendLayout();
			menuStrip1.SuspendLayout();
			SuspendLayout();
			groupBox1.Controls.Add(radioButton7);
			groupBox1.Controls.Add(radioButton4);
			groupBox1.Controls.Add(radioButton3);
			groupBox1.Controls.Add(radioButton2);
			groupBox1.Location = new System.Drawing.Point(33, 27);
			groupBox1.Name = "groupBox1";
			groupBox1.Size = new System.Drawing.Size(496, 62);
			groupBox1.TabIndex = 0;
			groupBox1.TabStop = false;
			groupBox1.Text = "查询类型";
			radioButton7.AutoSize = true;
			radioButton7.Location = new System.Drawing.Point(91, 30);
			radioButton7.Name = "radioButton7";
			radioButton7.Size = new System.Drawing.Size(71, 16);
			radioButton7.TabIndex = 5;
			radioButton7.TabStop = true;
			radioButton7.Text = "已穿装备";
			radioButton7.UseVisualStyleBackColor = true;
			radioButton4.AutoSize = true;
			radioButton4.Location = new System.Drawing.Point(283, 30);
			radioButton4.Name = "radioButton4";
			radioButton4.Size = new System.Drawing.Size(71, 16);
			radioButton4.TabIndex = 3;
			radioButton4.TabStop = true;
			radioButton4.Text = "综合仓库";
			radioButton4.UseVisualStyleBackColor = true;
			radioButton3.AutoSize = true;
			radioButton3.Location = new System.Drawing.Point(187, 30);
			radioButton3.Name = "radioButton3";
			radioButton3.Size = new System.Drawing.Size(71, 16);
			radioButton3.TabIndex = 2;
			radioButton3.TabStop = true;
			radioButton3.Text = "个人仓库";
			radioButton3.UseVisualStyleBackColor = true;
			radioButton2.AutoSize = true;
			radioButton2.Location = new System.Drawing.Point(19, 30);
			radioButton2.Name = "radioButton2";
			radioButton2.Size = new System.Drawing.Size(47, 16);
			radioButton2.TabIndex = 1;
			radioButton2.TabStop = true;
			radioButton2.Text = "背包";
			radioButton2.UseVisualStyleBackColor = true;
			groupBox2.Controls.Add(textBox1);
			groupBox2.Location = new System.Drawing.Point(33, 102);
			groupBox2.Name = "groupBox2";
			groupBox2.Size = new System.Drawing.Size(496, 386);
			groupBox2.TabIndex = 1;
			groupBox2.TabStop = false;
			groupBox2.Text = "查询记录";
			textBox1.Location = new System.Drawing.Point(19, 20);
			textBox1.Multiline = true;
			textBox1.Name = "textBox1";
			textBox1.Size = new System.Drawing.Size(458, 347);
			textBox1.TabIndex = 0;
			button1.Location = new System.Drawing.Point(435, 494);
			button1.Name = "button1";
			button1.Size = new System.Drawing.Size(75, 23);
			button1.TabIndex = 4;
			button1.Text = "开始查询";
			button1.UseVisualStyleBackColor = true;
			button1.Click += new System.EventHandler(button1_Click);
			menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[1]
			{
				说明ToolStripMenuItem
			});
			menuStrip1.Location = new System.Drawing.Point(0, 0);
			menuStrip1.Name = "menuStrip1";
			menuStrip1.Size = new System.Drawing.Size(567, 25);
			menuStrip1.TabIndex = 5;
			menuStrip1.Text = "menuStrip1";
			说明ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[1]
			{
				帮助ToolStripMenuItem
			});
			说明ToolStripMenuItem.Name = "说明ToolStripMenuItem";
			说明ToolStripMenuItem.Size = new System.Drawing.Size(44, 21);
			说明ToolStripMenuItem.Text = "说明";
			帮助ToolStripMenuItem.Name = "帮助ToolStripMenuItem";
			帮助ToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
			帮助ToolStripMenuItem.Text = "帮助";
			帮助ToolStripMenuItem.Click += new System.EventHandler(帮助ToolStripMenuItem_Click);
			base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			base.ClientSize = new System.Drawing.Size(567, 529);
			base.Controls.Add(button1);
			base.Controls.Add(groupBox2);
			base.Controls.Add(groupBox1);
			base.Controls.Add(menuStrip1);
			base.Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon");
			base.MainMenuStrip = menuStrip1;
			base.Name = "CheckCopy";
			Text = "查复制";
			base.FormClosing += new System.Windows.Forms.FormClosingEventHandler(CheckCopy_FormClosing);
			base.Load += new System.EventHandler(CheckCopy_Load);
			groupBox1.ResumeLayout(false);
			groupBox1.PerformLayout();
			groupBox2.ResumeLayout(false);
			groupBox2.PerformLayout();
			menuStrip1.ResumeLayout(false);
			menuStrip1.PerformLayout();
			ResumeLayout(false);
			PerformLayout();
		}

		private void SetText(string s)
		{
			if (textBox1.InvokeRequired)
			{
				MyInvoke method = SetText;
				Invoke(method, "\r\n" + s);
			}
			else
			{
				textBox1.Text = textBox1.Text + "\r\n" + s;
			}
		}

		private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			MessageBox.Show("数据量大的查询时间比较长,必须是停服维护(关闭LoginServer且无玩家登录)才能查询", "帮助");
		}

		private void 查物品(object ParObject)
		{
			ThreadParameter threadParameter = (ThreadParameter)ParObject;
			string text = "";
			string sqlCommand = "select FLD_ID,FLD_NAME,FLD_WEARITEM,FLD_ITEM from [TBL_人物数据] where FLD_NAME<>'" + threadParameter.name + "'";
			string sqlCommand2 = "select FLD_ID,FLD_NAME,FLD_ITEM from [TBL_个人仓库] where FLD_NAME<>'" + threadParameter.name + "'";
			string sqlCommand3 = "select FLD_ID,FLD_ITEM from [TBL_综合仓库] where FLD_ID<>'" + threadParameter.id + "'";
			switch (threadParameter.类型)
			{
			case 0:
				text = "背包";
				break;
			case 1:
				text = "已穿装备";
				break;
			case 2:
				text = "个人仓库";
				break;
			case 3:
				sqlCommand = "select FLD_ID,FLD_NAME,FLD_WEARITEM,FLD_ITEM from [TBL_人物数据]";
				sqlCommand2 = "select FLD_ID,FLD_NAME,FLD_ITEM from [TBL_个人仓库]";
				text = "综合仓库";
				break;
			}
			人物自身1 = DBA.GetDBToDataTable(sqlCommand, "GameServer");
			个人仓库1 = DBA.GetDBToDataTable(sqlCommand2, "GameServer");
			综合仓库1 = DBA.GetDBToDataTable(sqlCommand3, "GameServer");
			if (人物自身1.Rows.Count != 0)
			{
				for (int i = 0; i < 人物自身1.Rows.Count; i++)
				{
					byte[] src = (byte[])人物自身1.Rows[i]["FLD_ITEM"];
					byte[] src2 = (byte[])人物自身1.Rows[i]["FLD_WEARITEM"];
					人物自身1.Rows[i]["FLD_ID"].ToString();
					string text2 = 人物自身1.Rows[i]["FLD_NAME"].ToString();
					for (int j = 0; j < 36; j++)
					{
						byte[] array = new byte[4];
						Buffer.BlockCopy(src, j * 73, array, 0, 4);
						int num = BitConverter.ToInt32(array, 0);
						if (num != 0 && num == threadParameter.全局ID)
						{
							SetText("发现复制装备,物品全局ID[" + threadParameter.全局ID.ToString() + "],在人物【" + text2 + "】的背包栏和人物【" + threadParameter.name + "】的" + text);
						}
					}
					for (int k = 0; k < 15; k++)
					{
						byte[] array2 = new byte[4];
						Buffer.BlockCopy(src2, k * 73, array2, 0, 4);
						int num2 = BitConverter.ToInt32(array2, 0);
						if (num2 != 0 && num2 == threadParameter.全局ID)
						{
							SetText("发现复制装备,物品全局ID[" + threadParameter.全局ID.ToString() + "],在人物【" + text2 + "】的已穿装备栏和人物【" + threadParameter.name + "】的" + text);
						}
					}
				}
			}
			人物自身1.Dispose();
			if (个人仓库1.Rows.Count != 0)
			{
				for (int l = 0; l < 个人仓库1.Rows.Count; l++)
				{
					byte[] src3 = (byte[])个人仓库1.Rows[l]["FLD_ITEM"];
					string text3 = 个人仓库1.Rows[l]["FLD_NAME"].ToString();
					for (int m = 0; m < 60; m++)
					{
						byte[] array3 = new byte[4];
						Buffer.BlockCopy(src3, m * 73, array3, 0, 4);
						int num3 = BitConverter.ToInt32(array3, 0);
						if (num3 != 0 && num3 == threadParameter.全局ID)
						{
							SetText("发现复制装备,物品全局ID[" + threadParameter.全局ID.ToString() + "],在人物【" + text3 + "】的个人仓库和人物【" + threadParameter.name + "】的" + text);
						}
					}
				}
			}
			个人仓库1.Dispose();
			if (综合仓库1.Rows.Count != 0)
			{
				for (int n = 0; n < 综合仓库1.Rows.Count; n++)
				{
					byte[] src4 = (byte[])综合仓库1.Rows[n]["FLD_ITEM"];
					string text4 = 综合仓库1.Rows[n]["FLD_ID"].ToString();
					for (int num4 = 0; num4 < 60; num4++)
					{
						byte[] array4 = new byte[4];
						Buffer.BlockCopy(src4, num4 * 73, array4, 0, 4);
						int num5 = BitConverter.ToInt32(array4, 0);
						if (num5 != 0 && num5 == threadParameter.全局ID)
						{
							SetText("发现复制装备,物品全局ID[" + threadParameter.全局ID.ToString() + "],在帐号【" + text4 + "】的综合仓库和人物【" + threadParameter.name + "】的" + text);
						}
					}
				}
			}
			综合仓库1.Dispose();
		}
	}
}
